-- AnimationTalkM
-- create by chendh
-- 怪物动作发言
-- 用于处理怪物动作播放时发言的相关逻辑

module("AnimationTalkM", package.seeall);

-- 所有的动作发言配置信息
local animationTalkTable = {};

-- 载入配置表
local _init = false;
local loadCsv = function()
    if _init then return end
    _init = true;

    -- 转换下配置表
    local animationTalk_CSV = get_animation_talk_CSV();
    for i = 1, #animationTalk_CSV do
        local classId = animationTalk_CSV[i].class_id;
        local info = parseData(animationTalk_CSV[i]);
        if not animationTalkTable[classId] then
            animationTalkTable[classId] = { [info.action] = { [info.skill_id] = info, }, };
        else
            if not animationTalkTable[classId][info.action] then
                animationTalkTable[classId][info.action] = { [info.skill_id] = info, };
            else
                animationTalkTable[classId][info.action][info.skill_id] = info;
            end
        end
    end

    animationTalk_CSV = {};
end

-- 模块初始化
function init()
    loadCsv();
end

-- 解析数据
function parseData(data)
    if not data["skill_id"] or data["skill_id"] == 0 then
        data["skill_id"] = "default";
    end

    return data;
end

-- 检索信息
function query(id, path)
    local m = animationTalkTable[id]

    if not m or path == "" or not path then
        return m
    end

    return m[path]
end

-- 获取怪物指定行为下技能发言
function getActionSkillTalk(id, action, skillId)
    local monsterTalkInfo = animationTalkTable[id] or {};
    local actionInfo = monsterTalkInfo[action] or {};
    local skillTalk = actionInfo[skillId];

    -- 如果根据技能id没有找到发言内容，那么找同一行为下的默认发言
    if not skillTalk then
        skillTalk = actionInfo["default"];
    end

    -- 如果找过了默认发言还是没有找到，那么说明是没有了
    if not skillTalk then
        return {};
    end

    return skillTalk;
end

